package com.workflow.engine.eb.steps.al;

import com.workflow.engine.core.flow.StepState;
import com.workflow.engine.parser.annotation.PGConfig;
import com.workflow.engine.parser.annotation.PGScheme;
import com.workflow.engine.parser.constant.HttpMethod;
import com.workflow.engine.parser.flow.impl.AbstractStep;
import com.workflow.engine.parser.strategy.StrategyType;
import com.workflow.engine.parser.utils.StepStateUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.LinkedHashMap;
import java.util.Map;

import static com.workflow.engine.parser.constant.HttpMethod.POST;

/**
 * 腾讯登录请求
 * Created by houjinxin on 2017/2/23.
 */
@PGConfig({
        @PGScheme(requestParamName = "ua", strategy = StrategyType.FIXED, strategyNeedParams = "154n+qZ9mgNqgJnCG0WtMC3zbvMsMaxxr7be9s=|nOiH84T4jvSP84nwhvOF+Vk=|neiHGXz6UeRW5k4rRCFZIkcoTdd7ym3fZdO2FrY=|mu6b9JHpZ9F120LFQ81d73LcZNNDxHQPgPRfKJELmxG9D7QRh+JC|m++T/GIWeQ17AHYZZQpvB38DbwNv0X3UsRGx|mOOM6Yws|meWK74oq|luKW+WcCqR6pGqzRo9F1zXrRoASrB7QQrN17yXkLpBa8EKHTf85pwXoLoBenwq3IrQ2t|l+GOEGMMfxBkGGsdcgtzCGcTbxppBnIBeglmEm4baAdzAHcEpAQ=|lO6BH3rJbdtt12XQd9Vg1nLeb9xk07bZrcK1z7jAYMA=|leKNE3YTfAB1AW4ZYRh3D3wLfd19|kuiHGXzPa91r0WPWcdNm0HTYadpi1bDfrMO6wrjAYMA=|k+mGGH3Oatxq0GLXcNJn0XXZaNtj1LHeqsWxyb3EsxOz|kOeIFnMWeQV9BmkfZRZ5DXUNdwurCw==|keaJF3L/jyCSOJQlVfBH9pP8iP2J8p3rk+SL/4b1gPxc/A==|jvaZB2LvnzCCKIQ1ReBX5oPscgZzB3AfaRBkxKvYt9K32KzVodqsDKw=|j/WaBGHSdsB2zH7LbM57zWnFdMd/yK3Csd6q06fbrg6u|jPaZB2LvnzCCKIQ1ReBX5oPsmPeD+o/8hyeH|jfeYBmPunjGDKYU0ROFW54LtnvGE/ovzhiaG|iv2O/ZLhjvuU4JfjjPqC+Jfvk/yG/pHlkeaJ/ZLllvmA75nijfuB7pj3gu2Z6oXzheqc6YbwhCQ="),
        @PGScheme(requestParamName = "support", strategy = StrategyType.FIXED, strategyNeedParams = "000001"),
        @PGScheme(requestParamName = "superSwitch", strategy = StrategyType.FIXED, strategyNeedParams = "true"),
        @PGScheme(requestParamName = "sso_hid", strategy = StrategyType.FIXED, strategyNeedParams = ""),
        @PGScheme(requestParamName = "site", strategy = StrategyType.FIXED, strategyNeedParams = ""),
        @PGScheme(requestParamName = "security_activeX_enabled", strategy = StrategyType.FIXED, strategyNeedParams = "false"),
        @PGScheme(requestParamName = "REMOTE_PCID_NAME", strategy = StrategyType.FIXED, strategyNeedParams = "_seaside_gogo_pcid"),
        @PGScheme(requestParamName = "redirectType", strategy = StrategyType.FIXED, strategyNeedParams = ""),
        @PGScheme(requestParamName = "rds_form_token", strategy = StrategyType.FIXED, strategyNeedParams = "5KsakVDCKMoZkutMDm8L1h4vWMGioxbS"),
        @PGScheme(requestParamName = "qrCodeSecurityId", strategy = StrategyType.FIXED, strategyNeedParams = "web|authcenter_qrcode_login|5b80fb75-d1e8-42b1-8953-ec8c3fc0873dRZ24"), //页面
        @PGScheme(requestParamName = "preCheckTimes", strategy = StrategyType.FIXED, strategyNeedParams = "5"),
        @PGScheme(requestParamName = "personalLoginError", strategy = StrategyType.FIXED, strategyNeedParams = ""),
        @PGScheme(requestParamName = "passwordSecurityId", strategy = StrategyType.FIXED, strategyNeedParams = "web|authcenter_querypwd_login|829ea3bf-2c05-420f-b6cb-5e178388952cRZ24"), //页面
        @PGScheme(requestParamName = "password_rsainput", strategy = StrategyType.FIXED, strategyNeedParams = ""),
        @PGScheme(requestParamName = "password_input", strategy = StrategyType.FIXED, strategyNeedParams = ""),
        @PGScheme(requestParamName = "password", strategy = StrategyType.FIXED, strategyNeedParams = "WdAX+vaTgRsx2PZcP70uqBeHyolacV1ZhJDH09oNJ0IuwiWpNCJx3FNnf6Jxvx9rLA+w6UkZCItr9wLxTQf6P9viABh05+s+cTx7Lxi+yXzuvoUrgWgW0pdAbtRMMlAZZ3pDcpnlHpmGyphGyKWjPgbLLZbSV+bi7p4HgjrkNgOe+HKsTQHVX5hdNXIh1MimH6GvH7p4WGmPyBwAiVVBe7jEPjXjOM0q7QSee8BHjGpMbxt+Rqcizsemssw5XGGUEFBxRDwYWKXzdchymmbkFsKD06x1zsVnhrMigKiaKhVkl/+ah8dw5ifLSSVRbfil9+L3Uw35wFrrZOHU5q7ncw=="),
        @PGScheme(requestParamName = "noActiveX", strategy = StrategyType.FIXED, strategyNeedParams = "false"),
        @PGScheme(requestParamName = "needTransfer", strategy = StrategyType.FIXED, strategyNeedParams = ""),
        @PGScheme(requestParamName = "method", strategy = StrategyType.FIXED, strategyNeedParams = ""),
        @PGScheme(requestParamName = "logonId", strategy = StrategyType.FIXED, strategyNeedParams = "woshihoujinxin@163.com"),
        @PGScheme(requestParamName = "loginScene", strategy = StrategyType.FIXED, strategyNeedParams = "index"),
        @PGScheme(requestParamName = "json_tk", strategy = StrategyType.FIXED, strategyNeedParams = ""),
        @PGScheme(requestParamName = "J_aliedit_using", strategy = StrategyType.FIXED, strategyNeedParams = "true"),
        @PGScheme(requestParamName = "J_aliedit_uid_hidn", strategy = StrategyType.FIXED, strategyNeedParams = "alieditUid"),
        @PGScheme(requestParamName = "J_aliedit_prod_type", strategy = StrategyType.FIXED, strategyNeedParams = ""),
        @PGScheme(requestParamName = "J_aliedit_net_info", strategy = StrategyType.FIXED, strategyNeedParams = ""),
        @PGScheme(requestParamName = "J_aliedit_key_hidn", strategy = StrategyType.FIXED, strategyNeedParams = "password"),
        @PGScheme(requestParamName = "idPrefix", strategy = StrategyType.FIXED, strategyNeedParams = ""),
        @PGScheme(requestParamName = "goto", strategy = StrategyType.FIXED, strategyNeedParams = ""),
        @PGScheme(requestParamName = "errorVM", strategy = StrategyType.FIXED, strategyNeedParams = ""),
        @PGScheme(requestParamName = "errorGoto", strategy = StrategyType.FIXED, strategyNeedParams = ""),
        @PGScheme(requestParamName = "CtrlVersion", strategy = StrategyType.FIXED, strategyNeedParams = "1,1,0,1"),
        @PGScheme(requestParamName = "checkCode", strategy = StrategyType.FIXED, strategyNeedParams = ""),
        @PGScheme(requestParamName = "alieditUid", strategy = StrategyType.FIXED, strategyNeedParams = "371a34b35ad7317d9d26d43229d1750e"), //页面
        @PGScheme(requestParamName = "_seaside_gogo_pcid", strategy = StrategyType.FIXED, strategyNeedParams = ""),
        @PGScheme(requestParamName = "_seaside_gogo_p", strategy = StrategyType.FIXED, strategyNeedParams = ""),
        @PGScheme(requestParamName = "_seaside_gogo_", strategy = StrategyType.FIXED, strategyNeedParams = ""),
})
public class Alipay1 extends AbstractStep  {

    private static final Logger logger = LoggerFactory.getLogger(Alipay1.class);

    @Override
    public Logger getLogger() {
        return logger;
    }

    @Override
    protected String getRequestUrl() {
        return "https://authem14.alipay.com/login/index.htm";
    }

    @Override
    protected Map<String, String> getHeaders() {
        return new LinkedHashMap<String, String>(){{
            put("Host", "authem14.alipay.com");
            put("Connection", "keep-alive");
//            put("Content-Length", "2925");
            put("Cache-Control", "max-age=0");
            put("Origin", "https://auth.alipay.com");
            put("Upgrade-Insecure-Requests", "1");
            put("User-Agent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.81 Safari/537.36");
            put("Content-Type", "application/x-www-form-urlencoded");
            put("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
            put("Referer", "https://auth.alipay.com/login/index.htm?goto=https%3A%2F%2Fwww.alipay.com%2F");
            put("Accept-Encoding", "gzip, deflate, br");
            put("Accept-Language", "zh-CN,zh;q=0.8");
        }};
    }

    @Override
    protected HttpMethod getHttpMethod() {
        return POST;
    }

    @Override
    protected StepState handleResponse(Map<String, Object> context, Object response) throws Exception {
        logger.info("结果：{}", response);
        return StepStateUtil.successfulStepState(this);
    }
}
